/*
 * Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "hctest.h"
#include "cmsis_os.h"
#include "ohos_types.h"

#include "log.h"
#include "ohos_bt_gatt.h"
#include "ohos_bt_gatt_server.h"
#include "ohos_ble_test_config.h"

#define BLE_ADV_HANDLE_DEFAULT  1
#define BLE_UUID_SERVER_ID      1

#define OHOS_SERVICE_UUID       {0xfb,0x34,0x9b,0x5f,0x80,0x00,0x00,0x80,0x00,0x10,0x00,0x00,0x10,0xff,0x00,0x00}
#define OHOS_CHAR_UUID_WRITE    {0xfb,0x34,0x9b,0x5f,0x80,0x00,0x00,0x80,0x00,0x10,0x00,0x00,0x22,0xff,0x00,0x00}
#define OHOS_CHAR_UUID_READ     {0xfb,0x34,0x9b,0x5f,0x80,0x00,0x00,0x80,0x00,0x10,0x00,0x00,0x11,0xff,0x00,0x00}

enum {
    /** 蓝牙广播参数（默认参数） **/
    BT_ADV_PARMS_DEFAULT,
};

enum {
    BT_SYNC_STATE_NULL,
    BT_SYNC_STATE_ADV_ENABLE,
    BT_SYNC_STATE_ADV_DISABLE,
    BT_SYNC_STATE_ADV_DATA,
    BT_SYNC_STATE_ADD_SERVICE,
    BT_SYNC_STATE_ADD_CHARACTERISTIC,
    BT_SYNC_STATE_ADD_DESCRIPTOR,
    BT_SYNC_STATE_START_SERVICE,
    BT_SYNC_STATE_STOP_SERVICE,
    BT_SYNC_STATE_DELETE_SERVICE,
    BT_SYNC_STATE_CONNECT,
    BT_SYNC_STATE_DISCONNECT,
    BT_SYNC_STATE_MTU_CHANGE,
    BT_SYNC_STATE_WRITE,
    BT_SYNC_STATE_READ,
    BT_SYNC_STATE_NOTIFY,
    BT_SYNC_STATE_NOTIFY_ENABLE,
};

static int g_syncState = 0;
static osSemaphoreId_t g_syncSemId = NULL;

static const uint8_t g_ohosAdvData[] = {
    0x02, 0x01, 0x05,
    0xD, 0x09, 'K', 'a', 'i', 'H', 'o', 'n', 'g', '_', 't', 'e', 's', 't',
};

static const uint8_t g_ohosAdvRspData[] = {
    0x02, 0x0a, 0x00,
};

static BleAdvParams g_ohosAdvParamArray[] = {
    [BT_ADV_PARMS_DEFAULT] = {
        .minInterval = 0x30, .maxInterval = 0x60, .advType = 0, .ownAddrType = 0,
        .peerAddrType = 0, .peerAddr.addr = 0, .channelMap = 0x07, .txPower = 0, .duration = 0,
    },
};

static const uint8_t g_ohosAppUuid[] = {
    0x00, 0x00,
};

static const uint8_t g_ohosServiceUuid[] = {
    0xfb, 0x34, 0x9b, 0x5f, 0x80, 0x00, 0x00, 0x80, 0x00, 0x10, 0x00, 0x00, 0x10, 0xff, 0x00, 0x00,
};

static const uint8_t g_ohosCharacteristicWriteUuid[] = {
    0xfb, 0x34, 0x9b, 0x5f, 0x80, 0x00, 0x00, 0x80, 0x00, 0x10, 0x00, 0x00, 0x11, 0xff, 0x00, 0x00,
};

static const uint8_t g_ohosCharacteristicReadUuid[] = {
    0xfb, 0x34, 0x9b, 0x5f, 0x80, 0x00, 0x00, 0x80, 0x00, 0x10, 0x00, 0x00, 0x22, 0xff, 0x00, 0x00,
};

static const uint8_t g_ohosDescriptorUuid[] = {
    0x02, 0x29, 
};

static int g_connId = 0;
static int g_srvcHandle = 0;
static int g_charHandle = 0;
static int g_charWriteHandle = 0;
static int g_charReadHandle = 0;
static int g_despNotifyHandle = 0;

static int ohos_semaphore_acquire(int state)
{
    int result = -1;

    if (g_syncSemId != NULL) {
	    result = osSemaphoreAcquire(g_syncSemId, OHOS_TEST_BLE_SYNC_TIMEOUT);
	}

    if (result == 0 && g_syncState != state) {
        result = -1;
    }

    return result;
}

static int ohos_semaphore_release(int state)
{
    int result = -1;

    if (g_syncSemId != NULL) {
		result = osSemaphoreRelease(g_syncSemId);
        g_syncState = state;
	}

    return result;
}

static void ohos_advEnable_callback(int advId, int status)
{
    HILOG_DEBUG(0, "[BLUETOOTH_TEST] fun:%s, line:%d, advId:%d, status:%d\n",
        __FUNCTION__, __LINE__, advId, status);

    if (status == 0) {
        TEST_ASSERT_EQUAL_INT(0, ohos_semaphore_release(BT_SYNC_STATE_ADV_ENABLE));
    }
}

static void ohos_advDisable_callback(int advId, int status)
{
    HILOG_DEBUG(0, "[BLUETOOTH_TEST] fun:%s, line:%d, advId:%d, status:%d\n",
        __FUNCTION__, __LINE__, advId, status);

    if (status == 0) {
        TEST_ASSERT_EQUAL_INT(0, ohos_semaphore_release(BT_SYNC_STATE_ADV_DISABLE));
    }
}

static void ohos_advData_callback(int advId, int status)
{
    HILOG_DEBUG(0, "[BLUETOOTH_TEST] fun:%s, line:%d, advId:%d, status:%d\n",
        __FUNCTION__, __LINE__, advId, status);

    if (status == 0) {
        TEST_ASSERT_EQUAL_INT(0, ohos_semaphore_release(BT_SYNC_STATE_ADV_DATA));
    }
}

static BtGattCallbacks g_bleGapFunc = {
    .advEnableCb = ohos_advEnable_callback,
    .advDisableCb = ohos_advDisable_callback,
    .advDataCb = ohos_advData_callback,
};

static void ohos_connect_server_callback(int connId, int serverId, const BdAddr *bdAddr)
{
    HILOG_DEBUG(0, "[BLUETOOTH_TEST] fun:%s, line:%d, serverId:%d, connId:%d\n",
        __FUNCTION__, __LINE__, serverId, connId);

    g_connId = connId;
    TEST_ASSERT_EQUAL_INT(0, ohos_semaphore_release(BT_SYNC_STATE_CONNECT));
}

static void ohos_disconnect_server_callback(int connId, int serverId, const BdAddr *bdAddr)
{
    HILOG_DEBUG(0, "[BLUETOOTH_TEST] fun:%s, line:%d, serverId:%d, connId:%d\n",
        __FUNCTION__, __LINE__, serverId, connId);

    TEST_ASSERT_EQUAL_INT(0, ohos_semaphore_release(BT_SYNC_STATE_DISCONNECT));
}

static void ohos_service_add_callback(int status, int serverId, BtUuid *uuid, int srvcHandle)
{
    HILOG_DEBUG(0, "[BLUETOOTH_TEST] fun:%s, line:%d, serverId:%d, srvcHandle:%d\n",
        __FUNCTION__, __LINE__, serverId, srvcHandle);

    if (status == 0) {
        g_srvcHandle = srvcHandle;
        TEST_ASSERT_EQUAL_INT(0, ohos_semaphore_release(BT_SYNC_STATE_ADD_SERVICE));
    }
}

static void ohos_characteristic_add_callback(int status, int serverId, BtUuid *uuid,
                                          int srvcHandle, int characteristicHandle)
{
    HILOG_DEBUG(0, "[BLUETOOTH_TEST] fun:%s, line:%d, serverId:%d, srvcHandle:%d, characteristicHandle:%d\n",
        __FUNCTION__, __LINE__, serverId, srvcHandle, characteristicHandle);

    if (status == 0) {
        g_charHandle = characteristicHandle;
        TEST_ASSERT_EQUAL_INT(0, ohos_semaphore_release(BT_SYNC_STATE_ADD_CHARACTERISTIC));
    }
}

static void ohos_descriptor_add_callback(int status, int serverId, BtUuid *uuid,
                                      int srvcHandle, int descriptorHandle)
{
    HILOG_DEBUG(0, "[BLUETOOTH_TEST] fun:%s, line:%d, serverId:%d, srvcHandle:%d, descriptorHandle:%d\n",
        __FUNCTION__, __LINE__, serverId, srvcHandle, descriptorHandle);

    if (status == 0) {
        g_despNotifyHandle = descriptorHandle;
        TEST_ASSERT_EQUAL_INT(0, ohos_semaphore_release(BT_SYNC_STATE_ADD_DESCRIPTOR));
    }
}

static void ohos_service_start_callback(int status, int serverId, int srvcHandle)
{
    HILOG_DEBUG(0, "[BLUETOOTH_TEST] fun:%s, line:%d, serverId:%d, srvcHandle:%d, status:%d\n",
        __FUNCTION__, __LINE__, serverId, srvcHandle, status);

    if (status == 0 && srvcHandle == g_srvcHandle) {
        TEST_ASSERT_EQUAL_INT(0, ohos_semaphore_release(BT_SYNC_STATE_START_SERVICE));
    }
}

static void ohos_service_stop_callback(int status, int serverId, int srvcHandle)
{
    HILOG_DEBUG(0, "[BLUETOOTH_TEST] fun:%s, line:%d, serverId:%d, srvcHandle:%d, status:%d\n",
        __FUNCTION__, __LINE__, serverId, srvcHandle, status);

    if (status == 0) {
        TEST_ASSERT_EQUAL_INT(0, ohos_semaphore_release(BT_SYNC_STATE_STOP_SERVICE));
    }
}

static void ohos_service_delete_callback(int status, int serverId, int srvcHandle)
{
    HILOG_DEBUG(0, "[BLUETOOTH_TEST] fun:%s, line:%d, serverId:%d, srvcHandle:%d, status:%d\n",
        __FUNCTION__, __LINE__, serverId, srvcHandle, status);

    if (status == 0) {
        TEST_ASSERT_EQUAL_INT(0, ohos_semaphore_release(BT_SYNC_STATE_DELETE_SERVICE));
    }
}

static void ohos_request_read_callback(BtReqReadCbPara readCbPara)
{
    HILOG_DEBUG(0, "[BLUETOOTH_TEST] fun:%s, line:%d\n", __FUNCTION__, __LINE__);

    TEST_ASSERT_EQUAL_INT(0, ohos_semaphore_release(BT_SYNC_STATE_READ));
}

static void ohos_request_write_callback(BtReqWriteCbPara writeCbPara)
{
    int i = 0;
    int result = 0;
    uint8_t writeData[] = OHOS_TEST_WRITE_DATA;

    HILOG_DEBUG(0, "[BLUETOOTH_TEST] fun:%s, line:%d, handle:%d, value_len:%d\n",
        __FUNCTION__, __LINE__, writeCbPara.attrHandle, writeCbPara.length);
    HILOG_DEBUG(0, "write data:");
    for (i = 0; i < writeCbPara.length; i++) {
        HILOG_DEBUG(0, "0x%x ", writeCbPara.value[i]);
    }
    HILOG_DEBUG(0, "\n");

    if (writeCbPara.needRsp) {
        GattsSendRspParam response = {
            .connectId = writeCbPara.connId,
            .status = OHOS_GATT_SUCCESS,
            .attrHandle = writeCbPara.attrHandle,
            .valueLen = 0,
            .value = NULL,
        };
        result = BleGattsSendResponse(BLE_UUID_SERVER_ID, &response);
        TEST_ASSERT_EQUAL_INT(0, result);
    }

    if (writeCbPara.attrHandle == g_charWriteHandle \
        && writeCbPara.length == sizeof(writeData) \
        && (memcmp(writeData, writeCbPara.value, writeCbPara.length) == 0)) {
        TEST_ASSERT_EQUAL_INT(0, ohos_semaphore_release(BT_SYNC_STATE_WRITE));
    } else if (writeCbPara.attrHandle == g_despNotifyHandle \
        && writeCbPara.value[0] == 1) {
        TEST_ASSERT_EQUAL_INT(0, ohos_semaphore_release(BT_SYNC_STATE_NOTIFY_ENABLE));
    }
}

static void ohos_indication_sent_callback(int connId, int status)
{
    HILOG_DEBUG(0, "[BLUETOOTH_TEST] fun:%s, line:%d, status:%d\n", __FUNCTION__, __LINE__, status);

    if (status == 0) {
        TEST_ASSERT_EQUAL_INT(0, ohos_semaphore_release(BT_SYNC_STATE_NOTIFY));
    }
}

static void ohos_mtu_change_callback(int connId, int mtu)
{
    HILOG_DEBUG(0, "[BLUETOOTH_TEST] fun:%s, line:%d, mtu:%d\n", __FUNCTION__, __LINE__, mtu);

    TEST_ASSERT_EQUAL_INT(0, ohos_semaphore_release(BT_SYNC_STATE_MTU_CHANGE));
}

static BtGattServerCallbacks g_bleServerFunc = {
    .connectServerCb = ohos_connect_server_callback,
    .disconnectServerCb = ohos_disconnect_server_callback,
    .serviceAddCb = ohos_service_add_callback,
    .characteristicAddCb = ohos_characteristic_add_callback,
    .descriptorAddCb = ohos_descriptor_add_callback,
    .serviceStartCb = ohos_service_start_callback,
    .serviceStopCb = ohos_service_stop_callback,
    .serviceDeleteCb = ohos_service_delete_callback,
    .requestReadCb = ohos_request_read_callback,
    .requestWriteCb = ohos_request_write_callback,
    .indicationSentCb = ohos_indication_sent_callback,
    .mtuChangeCb = ohos_mtu_change_callback,
};

/**
 * @tc.desc      : register a test suite, this suite is used to test basic flow and interface dependency
 * @param        : subsystem name is bluetoothUnitest
 * @param        : module name is bluetoothServerlite
 * @param        : test suite name is UtilsFileFuncTestSuite
 */
LITE_TEST_SUIT(BluetoothUnitest, BluetoothServerlite, BtServerBaseTestSuite);

/**
 * @tc.setup     : setup for all testcases
 * @return       : setup result, TRUE is success, FALSE is fail
 */
static BOOL BtServerBaseTestSuiteSetUp(void)
{
    HILOG_DEBUG(0, "+------------------ %s:%d ------------------+\r\n", __FUNCTION__, __LINE__);
	g_syncSemId = osSemaphoreNew(1, 0 ,NULL);
    TEST_ASSERT_NOT_NULL(g_syncSemId);
    return TRUE;
}

/**
 * @tc.teardown  : teardown for all testcases
 * @return       : teardown result, TRUE is success, FALSE is fail
 */
static BOOL BtServerBaseTestSuiteTearDown(void)
{
    HILOG_DEBUG(0, "+------------------ %s:%d ------------------+\r\n", __FUNCTION__, __LINE__);
    if(g_syncSemId != NULL) {
		osSemaphoreDelete(g_syncSemId);
		g_syncSemId = NULL;
	}
    return TRUE;
}

/**
 * @tc.number    : TestBleEnable
 * @tc.name      : bluetooth operation for enable
 * @tc.desc      : [C- SOFTWARE -0200]
 */
LITE_TEST_CASE(BtServerBaseTestSuite, TestBleEnable, Function | MediumTest | Level1)
{
    bool result = true;
	result = EnableBle();
    TEST_ASSERT_EQUAL_INT(true, result);
};

/**
 * @tc.number    : TestBleRegisterCallbcaks
 * @tc.name      : bluetooth operation for register callbacks
 * @tc.desc      : [C- SOFTWARE -0200]
 */
LITE_TEST_CASE(BtServerBaseTestSuite, TestBleRegisterCallbcaks, Function | MediumTest | Level1)
{
    int result = 0;
	result = BleGattRegisterCallbacks(&g_bleGapFunc);
    TEST_ASSERT_EQUAL_INT(0, result);
    result = BleGattsRegisterCallbacks(&g_bleServerFunc);
    TEST_ASSERT_EQUAL_INT(0, result);
};

/**
 * @tc.number    : TestBleSetAdvDate
 * @tc.name      : bluetooth operation for set adv data
 * @tc.desc      : [C- SOFTWARE -0200]
 */
LITE_TEST_CASE(BtServerBaseTestSuite, TestBleSetAdvDate, Function | MediumTest | Level1)
{
    int result = 0;
    StartAdvRawData rawData;
    rawData.advData = g_ohosAdvData;
    rawData.advDataLen = sizeof(g_ohosAdvData);
    rawData.rspData = g_ohosAdvRspData;
	rawData.rspDataLen = sizeof(g_ohosAdvRspData);
	result = BleSetAdvData(BLE_ADV_HANDLE_DEFAULT, rawData);
    TEST_ASSERT_EQUAL_INT(0, result);
    TEST_ASSERT_EQUAL_INT(0, ohos_semaphore_acquire(BT_SYNC_STATE_ADV_DATA));
};

/**
 * @tc.number    : TestBleSatrtAdv
 * @tc.name      : bluetooth operation for start adv
 * @tc.desc      : [C- SOFTWARE -0200]
 */
LITE_TEST_CASE(BtServerBaseTestSuite, TestBleSatrtAdv, Function | MediumTest | Level1)
{
    int result = 0;
	result = BleStartAdv(BLE_ADV_HANDLE_DEFAULT, &g_ohosAdvParamArray[BT_ADV_PARMS_DEFAULT]);
    TEST_ASSERT_EQUAL_INT(0, result);
    TEST_ASSERT_EQUAL_INT(0, ohos_semaphore_acquire(BT_SYNC_STATE_ADV_ENABLE));
};

/**
 * @tc.number    : TestBleGattsRegister
 * @tc.name      : bluetooth operation for register gatts
 * @tc.desc      : [C- SOFTWARE -0200]
 */
LITE_TEST_CASE(BtServerBaseTestSuite, TestBleGattsRegister, Function | MediumTest | Level1)
{
    int result = 0;
    BtUuid appUuid = {0};
    appUuid.uuidLen = sizeof(g_ohosAppUuid);
    appUuid.uuid = g_ohosAppUuid;
	result = BleGattsRegister(appUuid);
    TEST_ASSERT_EQUAL_INT(0, result);
};

/**
 * @tc.number    : TestBleGattsAddService
 * @tc.name      : bluetooth operation for add service
 * @tc.desc      : [C- SOFTWARE -0200]
 */
LITE_TEST_CASE(BtServerBaseTestSuite, TestBleGattsAddService, Function | MediumTest | Level1)
{
    int result = 0;
    BtUuid srvcUuid = {0};
    srvcUuid.uuidLen = sizeof(g_ohosServiceUuid);
    srvcUuid.uuid = g_ohosServiceUuid;
	result = BleGattsAddService(BLE_UUID_SERVER_ID, srvcUuid, true, 1);
    TEST_ASSERT_EQUAL_INT(0, result);
    TEST_ASSERT_EQUAL_INT(0, ohos_semaphore_acquire(BT_SYNC_STATE_ADD_SERVICE));
};

/**
 * @tc.number    : TestBleGattsAddWriteCharacteristic
 * @tc.name      : bluetooth operation for add write characteristic
 * @tc.desc      : [C- SOFTWARE -0200]
 */
LITE_TEST_CASE(BtServerBaseTestSuite, TestBleGattsAddWriteCharacteristic, Function | MediumTest | Level1)
{
    int result = 0;
    BtUuid characUuid = {0};
    characUuid.uuidLen = sizeof(g_ohosCharacteristicWriteUuid);
    characUuid.uuid = g_ohosCharacteristicWriteUuid;
	result = BleGattsAddCharacteristic(BLE_UUID_SERVER_ID, g_srvcHandle, characUuid,
        OHOS_GATT_CHARACTER_PROPERTY_BIT_WRITE, OHOS_GATT_PERMISSION_READ);
    TEST_ASSERT_EQUAL_INT(0, result);
    TEST_ASSERT_EQUAL_INT(0, ohos_semaphore_acquire(BT_SYNC_STATE_ADD_CHARACTERISTIC));
    g_charWriteHandle = g_charHandle;
};

/**
 * @tc.number    : TestBleGattsAddReadCharacteristic
 * @tc.name      : bluetooth operation for add read characteristic
 * @tc.desc      : [C- SOFTWARE -0200]
 */
LITE_TEST_CASE(BtServerBaseTestSuite, TestBleGattsAddReadCharacteristic, Function | MediumTest | Level1)
{
    int result = 0;
    BtUuid characUuid = {0};
    characUuid.uuidLen = sizeof(g_ohosCharacteristicReadUuid);
    characUuid.uuid = g_ohosCharacteristicReadUuid;
	result = BleGattsAddCharacteristic(BLE_UUID_SERVER_ID, g_srvcHandle, characUuid,
        OHOS_GATT_CHARACTER_PROPERTY_BIT_READ | OHOS_GATT_CHARACTER_PROPERTY_BIT_NOTIFY, OHOS_GATT_PERMISSION_READ);
    TEST_ASSERT_EQUAL_INT(0, result);
    TEST_ASSERT_EQUAL_INT(0, ohos_semaphore_acquire(BT_SYNC_STATE_ADD_CHARACTERISTIC));
    g_charReadHandle = g_charHandle;

    BtUuid descUuid = {0};
    descUuid.uuidLen = sizeof(g_ohosDescriptorUuid);
    descUuid.uuid = g_ohosDescriptorUuid;
    result = BleGattsAddDescriptor(BLE_UUID_SERVER_ID, g_srvcHandle, descUuid, 
        OHOS_GATT_PERMISSION_READ | OHOS_GATT_PERMISSION_WRITE);
    TEST_ASSERT_EQUAL_INT(0, result);
    TEST_ASSERT_EQUAL_INT(0, ohos_semaphore_acquire(BT_SYNC_STATE_ADD_DESCRIPTOR));
};

/**
 * @tc.number    : TestBleGattsStartService
 * @tc.name      : bluetooth operation for start service
 * @tc.desc      : [C- SOFTWARE -0200]
 */
LITE_TEST_CASE(BtServerBaseTestSuite, TestBleGattsStartService, Function | MediumTest | Level1)
{
    int result = 0;
    result = BleGattsStartService(BLE_UUID_SERVER_ID, g_srvcHandle);
    TEST_ASSERT_EQUAL_INT(0, result);
    TEST_ASSERT_EQUAL_INT(0, ohos_semaphore_acquire(BT_SYNC_STATE_START_SERVICE));
};

#ifdef OHOS_TEST_SUPPORT_CLIENT_INTERACTION

/**
 * @tc.number    : TestBleWaitClientConnect
 * @tc.name      : bluetooth operation for wait client connect
 * @tc.desc      : [C- SOFTWARE -0200]
 */
LITE_TEST_CASE(BtServerBaseTestSuite, TestBleWaitClientConnect, Function | MediumTest | Level1)
{
    TEST_ASSERT_EQUAL_INT(0, ohos_semaphore_acquire(BT_SYNC_STATE_CONNECT));
};

/**
 * @tc.number    : TestBleWaitMTUChange
 * @tc.name      : bluetooth operation for wait mtu change
 * @tc.desc      : [C- SOFTWARE -0200]
 */
LITE_TEST_CASE(BtServerBaseTestSuite, TestBleWaitMTUChange, Function | MediumTest | Level1)
{
    TEST_ASSERT_EQUAL_INT(0, ohos_semaphore_acquire(BT_SYNC_STATE_MTU_CHANGE));
};

/**
 * @tc.number    : TestBleWaitWrite
 * @tc.name      : bluetooth operation for wait write
 * @tc.desc      : [C- SOFTWARE -0200]
 */
LITE_TEST_CASE(BtServerBaseTestSuite, TestBleWaitWrite, Function | MediumTest | Level1)
{
    TEST_ASSERT_EQUAL_INT(0, ohos_semaphore_acquire(BT_SYNC_STATE_WRITE));
};

/**
 * @tc.number    : TestBleWaitRead
 * @tc.name      : bluetooth operation for wait read
 * @tc.desc      : [C- SOFTWARE -0200]
 */
LITE_TEST_CASE(BtServerBaseTestSuite, TestBleWaitRead, Function | MediumTest | Level1)
{
    TEST_ASSERT_EQUAL_INT(0, ohos_semaphore_acquire(BT_SYNC_STATE_READ));
};

/**
 * @tc.number    : TestBleWaitNotify
 * @tc.name      : bluetooth operation for wait notify enable and norify
 * @tc.desc      : [C- SOFTWARE -0200]
 */
LITE_TEST_CASE(BtServerBaseTestSuite, TestBleWaitNotify, Function | MediumTest | Level1)
{
    int result = 0;
    GattsSendIndParam sendParam;
    uint8_t notifyData[] = OHOS_TEST_NOTIFY_DATA;

    TEST_ASSERT_EQUAL_INT(0, ohos_semaphore_acquire(BT_SYNC_STATE_NOTIFY_ENABLE));

	sendParam.confirm = 0;
    sendParam.valueLen = sizeof(notifyData);
	sendParam.value = notifyData;
    sendParam.attrHandle = g_charReadHandle;
    sendParam.connectId = g_connId;
    result = BleGattsSendIndication(BLE_UUID_SERVER_ID, &sendParam);
    TEST_ASSERT_EQUAL_INT(0, result);
    TEST_ASSERT_EQUAL_INT(0, ohos_semaphore_acquire(BT_SYNC_STATE_NOTIFY));
};

/**
 * @tc.number    : TestBleWaitDisconnect
 * @tc.name      : bluetooth operation for wait disconnect
 * @tc.desc      : [C- SOFTWARE -0200]
 */
LITE_TEST_CASE(BtServerBaseTestSuite, TestBleWaitDisconnect, Function | MediumTest | Level1)
{
    TEST_ASSERT_EQUAL_INT(0, ohos_semaphore_acquire(BT_SYNC_STATE_DISCONNECT));
};

#endif // OHOS_BLE_SUPPORT_CLIENT_INTERACTION

/**
 * @tc.number    : TestBleGattsStopService
 * @tc.name      : bluetooth operation for stop service
 * @tc.desc      : [C- SOFTWARE -0200]
 */
LITE_TEST_CASE(BtServerBaseTestSuite, TestBleGattsStopService, Function | MediumTest | Level1)
{
    int result = 0;
    result = BleGattsStopService(BLE_UUID_SERVER_ID, g_srvcHandle);
    TEST_ASSERT_EQUAL_INT(0, result);
    // TEST_ASSERT_EQUAL_INT(0, ohos_semaphore_acquire(BT_SYNC_STATE_STOP_SERVICE));
};

/**
 * @tc.number    : TestBleGattsDeleteService
 * @tc.name      : bluetooth operation for delete service
 * @tc.desc      : [C- SOFTWARE -0200]
 */
LITE_TEST_CASE(BtServerBaseTestSuite, TestBleGattsDeleteService, Function | MediumTest | Level1)
{
    int result = 0;
    result = BleGattsDeleteService(BLE_UUID_SERVER_ID, g_srvcHandle);
    TEST_ASSERT_EQUAL_INT(0, result);
    TEST_ASSERT_EQUAL_INT(0, ohos_semaphore_acquire(BT_SYNC_STATE_DELETE_SERVICE));
};

/**
 * @tc.number    : TestBleStopAdv
 * @tc.name      : bluetooth operation for stop adv
 * @tc.desc      : [C- SOFTWARE -0200]
 */
LITE_TEST_CASE(BtServerBaseTestSuite, TestBleStopAdv, Function | MediumTest | Level1)
{
    int result = 0;
    result = BleStopAdv(BLE_ADV_HANDLE_DEFAULT);
    TEST_ASSERT_EQUAL_INT(0, result);
    TEST_ASSERT_EQUAL_INT(0, ohos_semaphore_acquire(BT_SYNC_STATE_ADV_DISABLE));
};

/**
 * @tc.number    : TestBleDisable
 * @tc.name      : bluetooth operation for disable
 * @tc.desc      : [C- SOFTWARE -0200]
 */
LITE_TEST_CASE(BtServerBaseTestSuite, TestBleDisable, Function | MediumTest | Level1)
{
    bool result = true;
    result = DisableBle();
    TEST_ASSERT_EQUAL_INT(true, result);
};

RUN_TEST_SUITE(BtServerBaseTestSuite);
